package com.itheima.mybatistest;

import com.itheima.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;


public class MyBatisTest1 {

    @Test
    public void test1() throws IOException {
        //加载mybatis核心配置文件
        InputStream resourceAsStream = Resources.getResourceAsStream("SqlMapConfig.xml");
        //获取sessionFactory工厂对象
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        //获取sqlSession会话对象
        SqlSession sqlSession = sessionFactory.openSession();
        //执行sql语句 参数:namespace.selectId
        List<User> userList = sqlSession.selectList("userMapper.findAll");
        System.out.println(userList);
        //释放sqlSession会话对象
        sqlSession.close();
    }
}
